package com.medical.medical.service;

import com.medical.medical.entity.Department;
import com.medical.medical.entity.Doctor;
import com.medical.medical.entity.WorkForces;
import com.medical.medical.mapper.DepartmentMapper;
import com.medical.medical.mapper.DoctorManageMapper;
import com.medical.medical.mapper.DoctorMapper;
import com.medical.medical.mapper.WorkForcesMapper;
import com.medical.medical.util.Constants;
import com.medical.medical.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @authorDesc 诸神在上，佑我程序，玄功护体，BUG皆去！
 * @author LiSuYang
 * @Date 2022-09-14 09:35:28
 * @version 1.0.0
 * @description 排班表-业务逻辑层实现类
 */
@Service
@Transactional
@Slf4j
public class WorkForcesServiceImpl implements WorkForcesService{
    @Resource
    private WorkForcesMapper workForcesMapper;
    @Resource
    private DoctorMapper doctorMapper;
    @Resource
    private DoctorManageMapper doctorManageMapper;

    @Override
    public List<WorkForces> getWordByKidAndDid(Integer workforcesDepartment, Integer workforcesDoctor) {
        List<WorkForces> workForcesList = null;
        try {
            workForcesList = workForcesMapper.getWordByKidAndDid(workforcesDepartment,workforcesDoctor);
        }catch (Exception e){
            e.printStackTrace();
        }
        return workForcesList;
    }

    /**
     * 根据科室id获取排班表信息条数
     * @param workforcesDepartment
     * @return
     */
    @Override
    public int getWorkCount(Integer workforcesDepartment) {
        int workCount=0;
        try {
            workCount=workForcesMapper.getWorkCount(workforcesDepartment);
        }catch (Exception e){
            e.printStackTrace();
            log.info("获取总条数时发生异常");
        }
        return workCount;
    }

    /**
     * 根据科室id查询排班表信息，并分页
     * @param workforcesDepartment
     * @param current
     * @return
     */
    @Override
    public Map<String, Object> getWorkForcesList(Integer workforcesDepartment, int current) {
        Map<String,Object> resultMap= ResultUtil.success("排班信息获取成功");
        int start=(current-1)* Constants.PAGE_SIZE;
        try {
            List<WorkForces> workForcesList=workForcesMapper.getWorkList(workforcesDepartment,start,Constants.PAGE_SIZE);
            if (workForcesList!=null && !workForcesList.isEmpty()){
                resultMap.put("workForcesList",workForcesList);
            }else {
                resultMap=ResultUtil.successNull("查询不到排班信息");
            }
            log.info("查询结束：{}",resultMap.get("message"));
            return resultMap;
        }catch (Exception e){
            e.printStackTrace();
            log.info("程序异常");
        }
        return ResultUtil.error("排班信息获取失败");
    }

    /**
     * 根据医生姓名和科室id查询医生个人的排班信息
     * @param workforcesDoctor
     * @param workforcesDepartment
     * @return
     */
    @Override
    public Map<String, Object> getWorkBydName(Integer workforcesDoctor, Integer workforcesDepartment) {
        Map<String,Object> resultMap=ResultUtil.success("医生个人排班查询成功");
        try {
            List<WorkForces> workForcesList=workForcesMapper.getWorkBydName(workforcesDoctor,workforcesDepartment);
            if (workForcesList!=null &&!workForcesList.isEmpty()){
                resultMap.put("workForcesList",workForcesList);
            }else {
                resultMap=ResultUtil.successNull("查询不到排班记录");
            }
            log.info("查询结束:{}",resultMap.get("message"));
            return resultMap;
        }catch (Exception e){
            e.printStackTrace();
            log.info("程序异常");
        }
        return ResultUtil.error("医生个人排班查询失败");
    }
}
